#ifndef MOCKSERVERHANDLER_H
#define MOCKSERVERHANDLER_H

#include <QThread>
#include <QSharedPointer>
#include <QTcpSocket>
#include <QTest>
#include <QHostAddress>
#include <string>
#include <iostream>

#include "wireformat.h"
#include "payload.h"
#include "anyevent.h"
#include "concurrentqueue.h"

class MockServerHandler2 : public QThread
{
	Q_OBJECT

public:
	MockServerHandler2(int socketDescriptor, QObject *parent = NULL);
	~MockServerHandler2();
	void write(char* data, int size);
	void stop();
	void sendEvent(QEvent* event) {mailbox.enqueue(event);}
signals:
	void error(QString ip, int port, QTcpSocket::SocketError socketError);

protected:
    virtual void run();
	
public slots:
	void read();
	void error2(QAbstractSocket::SocketError socketError);
	
private:
	QSharedPointer<QTcpSocket> socket;
	int socketDescriptor;
	volatile bool stopped;

	apollo::core::ConcurrentQueue<QEvent*> mailbox;

	apollo::core::WireFormat format;
	apollo::core::WireFormat::ReadingContext ctx;

};

#endif // MOCKSERVERHANDLER_H
